let baseURL

const request = ({url, method = 'GET', data, header = {}} = {}) => {
  if (url.startsWith('http')) {
    baseURL = ''
  } else {
    baseURL = 'http://www.xiongmaoyouxuan.com'
  }
  return new Promise((resolve, reject) => {
    uni.request({
      url: baseURL + url,
      method,
      data,
      header: {
        token: 'asdf;jaksdflj',
        ...header
      },
      success(resData) {
        if (resData.statusCode === 200) {
          const {code, data, status} = resData.data
          if (code === 200 || status === 0) {
            resolve(data)
            return
          }
        }
        reject(resData)
      },
      fail(err) {
        reject(err)
      }
    })
  })
}

export default request
